package com.info.game;


import java.util.HashMap;
import com.component.game.AIComponent;
import com.component.game.Component;
import com.engine.game.GameObject;


public class LabelAIComponent implements AIComponent{

	public boolean needToCheck = true;
	
	public static HashMap<Integer, SquareRenderComponent.Color> colors = new HashMap<Integer, SquareRenderComponent.Color>();
	
	
	@Override
	public void dispose() {
		
		
	}

	@Override
	public void update(GameObject object) {
		
		if(this.needToCheck){
		
		if(LabelAIComponent.colors.size() == 196){
			
			if(FloodItConfiguration.isBlocked){
				
				if(this.checkForWin()){
					object.generate("needed;win", "LABEL", Component.Render);
				}
				else{
					object.generate("needed;lose", "LABEL", Component.Render);
				}
				
				this.needToCheck = false;
				
			}
			else{
				if(this.checkForWin()){
					object.generate("needed;win", "LABEL", Component.Render);
					FloodItConfiguration.isBlocked = true;
					this.needToCheck = false;
				}
				
				
			}
			
			
		}
			
		}
		
	
		LabelAIComponent.colors.clear();
		
	}
	
	private boolean checkForWin(){
		SquareRenderComponent.Color tmp = LabelAIComponent.colors.get(1);
		
		boolean b = true;
		
		for(Integer cl : LabelAIComponent.colors.keySet()){
			if(!tmp.equals(LabelAIComponent.colors.get(cl))){
				b = false;
				break;
			}
		}
		
		return b;
		
	}

}
